package com.jhd.fuzhou.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;

public class DialogSize {
    public static void setDialogSize(View mView, Context context) {
        mView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                                       int oldRight, int oldBottom) {
                int heightNow = v.getHeight();//dialog当前的高度
                int widthNow = v.getWidth();//dialog当前的宽度
                int needHeight = (int) (((Activity)context).getWindowManager().getDefaultDisplay().getHeight() * 0.75);//最大高度为屏幕的0.6倍
                if (heightNow >needHeight) {
                    needHeight = FrameLayout.LayoutParams.WRAP_CONTENT;
                }
                mView.setLayoutParams(new FrameLayout.LayoutParams(widthNow,needHeight));
            }
        });
    }
}
